package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.Scanner;

public class JDBCDemo12 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String username = sc.next();
        try (Connection connection = DBUtil.getConnection();
             Statement statement = connection.createStatement()) {

            String sql = "delete from userinfo\n" +
                    "where username = ?";
            PreparedStatement pr = connection.prepareStatement(sql);
            pr.setString(1,username);
            int num = pr.executeUpdate();
            System.out.println(num > 0 ? "删除成功！" : "删除失败！");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
